﻿#if WINDOWS_PHONE_APP
using Windows.ApplicationModel.Email;
#endif
using Windows.Foundation;
using Windows.Storage;

namespace Enough.Lifecycle.Helper
{
    public static class EmailHelper
    {
        public static IAsyncAction ComposeEmailAsync(string to = null, string cc = null, string bcc = null, string subject = null, string body = null, params IStorageFile[] attachments)
        {
#if WINDOWS_PHONE_APP
            EmailMessage message = new EmailMessage();
            if (to != null)
            {
                foreach (string address in to.Split(';'))
                {
                    message.To.Add(new EmailRecipient(address));
                }
            }
            if (cc != null)
            {
                foreach (string address in cc.Split(';'))
                {
                    message.CC.Add(new EmailRecipient(address));
                }
            }
            if (bcc != null)
            {
                foreach (string address in bcc.Split(';'))
                {
                    message.CC.Add(new EmailRecipient(address));
                }
            }
            if (subject != null)
            {
                message.Subject = subject;
            }
            if (body != null)
            {
                message.Body = body;
            }
            if (attachments != null)
            {
                foreach (StorageFile attachement in attachments)
                {
                    message.Attachments.Add(new EmailAttachment(attachement.Name,  attachement));
                }
            }
            return EmailManager.ShowComposeNewEmailAsync(message);
#else
            return null;
#endif
        }
    }
}
